<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Db;
use \think\Loader;
class Authcate extends Controller
{
    public function index()
    {
        $data = Db::table('auth_cate')->select();
        // ->paginate(1);
        return $this->fetch('',['data'=>$data]);
    }

    public function addsubmit(){
        $data = input('post.');
        $insertData['cname'] = $data['cate_name'];
        $validate = Loader::validate('Admin');
        if(!$validate->scene('auth_cate')->check($insertData)){
            return ['error'=>1,'info'=>$validate->getError()];
        }

        $res = Db::table('auth_cate')->insert($insertData);
        if ($res) {
        	return ['error'=>0,'info'=>'success'];
        }else{
        	return ['error'=>1,'info'=>'增加分类失败'];
        }

    }

    public function del()
    {
    	$data = input('post.');
    	$res = Db::table('auth_cate')->where('cid','in',$data['data'])->delete();
    	// var_dump($res);exit;
    	if ($res) {
    		return ['error'=>0,'info'=>'操作成功'];
    	}else{
    		return ['error'=>1,'info'=>'操作失败,系统异常'];
    	}
    }

}


?>